package com.qf.controller;

import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.qf.pojo.adress;
import com.qf.pojo.discover;
import com.qf.service.DiscoverService;
import com.qf.vo.Msg;
import jdk.nashorn.internal.runtime.linker.LinkerCallSite;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by ZhaoHuiDong on 2020/9/16.
 */
@Controller
@RequestMapping("discover")
public class DiscoverController {
    @Autowired
    private DiscoverService discoverService;
    @RequestMapping("select")
    @ResponseBody
    public Msg<discover> selectAll(){
        List<discover> list = discoverService.selectAll();
        Msg<discover> msg = new Msg<>();
        msg.setData(list);
        return msg;
    }
    @RequestMapping("delete/{id}")
    @ResponseBody
    public Msg<discover> delete(@PathVariable("id") int id){
        Msg<discover> msg = new Msg<>();
        int delete = discoverService.delete(id);
        if(delete == 1){
            msg.setMsg("删除成功");
            return msg;
        }
        return null;
    }
    @RequestMapping("add")
    @ResponseBody
    public Msg<discover> add(discover discover){
        Msg<discover> msg = new Msg<>();
        int add = discoverService.add(discover);
        if(add == 1){
            msg.setMsg("添加成功");
            return msg;
        }
        return  null;
    }
    @RequestMapping("update")
    @ResponseBody
    public Msg<discover> update(discover discover){
        Msg<discover> msg = new Msg<>();
        int update = discoverService.update(discover);
        if(update == 1){
            msg.setMsg("修改成功");
            return null;
        }
        return null;
    }
}
